package com.groupsix.controller;

import com.groupsix.entity.Dormrepair;
import com.groupsix.service.DormRepairService;
import com.groupsix.utils.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author 董盛昌
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: 维修登记控制器
 * @date 2021/10/17 15:46
 */
@Controller
public class DormrepairController {
    // 依赖注入
    @Autowired
    private DormRepairService dormRepairService;

    /**
     * 分页查询
     * pageIndex 当前页码
     * pageSize  显示条数
     */
    @RequestMapping("/findDormRepair.action")
    public String findDormRepair(Integer dId,String dDormbuilding,
                                 Integer pageIndex, Integer pageSize, Model model) {

        PageInfo di = dormRepairService.findPageInfo(dId,dDormbuilding,
                pageIndex,pageSize);
        model.addAttribute("di",di);
        return "dormrepair_list";
    }


    /**
     * 添加宿舍信息
     */
    @RequestMapping("/addDormRepair.action")
    public String addDormitory( @RequestBody Dormrepair dormrepair) {
        int d = dormRepairService.addDormRepair(dormrepair);
        return "dormrepair_list";
    }

    /**
     * 删除宿舍信息
     */
    @RequestMapping( "/deleteDormRepair.action")
    @ResponseBody
    public String deleteDormRepair(Integer rId) {
        int d = dormRepairService.deleteDormRepair(rId);
        return "dormrepair_list";
    }

    /**
     * 修改学生信息
     */
    @RequestMapping( "/updateDormRepair.action")
    public String updateDormRepair( Dormrepair dormrepair) {
        int d = dormRepairService.updateDormRepair(dormrepair);
        return "redirect:/findDormRepair.action";
    }


    @RequestMapping( "/findDormRepairById.action")
    public String findDormRepairById(Integer rId, HttpSession session) {

        Dormrepair d= dormRepairService.findDormRepairById(rId);
        session.setAttribute("d",d);
        return "dormrepair_edit";
    }

}
